<template>
  <ych-modal
    :fullscreen="false"
    :title="title"
    :visible="visible"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form>

        <a-row>
          <a-col :span="24">
            <a-form-item :label="$t('m.eform.apptable.other.form_show_type')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select v-model="type" :placeholder="$t('m.eform.apptable.placeholder.form_show_type')" allowClear :disabled="true">
                <a-select-option v-for="item in showTypeOptions" :key="item.value" :value="item.value">
                  {{item.text}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24" v-show="config[type] && config[type]['placeholder']">
            <a-form-item :label="$t('m.eform.apptable.other.form_placeholder')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="placeholder" :placeholder="$t('m.eform.apptable.placeholder.form_placeholder')" allowClear/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="type === 'date'">
            <a-form-item :label="$t('m.eform.apptable.other.form_date')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select v-model="format" :placeholder="$t('m.eform.apptable.placeholder.form_date')" allowClear>
                <a-select-option value="YYYY">YYYY</a-select-option>
                <a-select-option value="YYYY-MM">YYYY-MM</a-select-option>
                <a-select-option value="YYYY-MM-DD">YYYY-MM-DD</a-select-option>
                <a-select-option value="YYYY/MM/DD">YYYY/MM/DD</a-select-option>
                <a-select-option value="YYYY-MM-DD HH">YYYY-MM-DD HH</a-select-option>
                <a-select-option value="YYYY-MM-DD HH:mm">YYYY-MM-DD HH:mm</a-select-option>
                <a-select-option value="YYYY-MM-DD HH:mm:ss">YYYY-MM-DD HH:mm:ss</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="type === 'time'">
            <a-form-item :label="$t('m.eform.apptable.other.form_time')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select v-model="format" :placeholder="$t('m.eform.apptable.placeholder.form_time')" allowClear>
                <a-select-option value="HH">HH</a-select-option>
                <a-select-option value="HH:mm">HH:mm</a-select-option>
                <a-select-option value="HH:mm:ss">HH:mm:ss</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['options']">
            <a-form-item :label="$t('m.eform.apptable.other.form_options')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <KChangeOption v-model="options" :group-id="groupId"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['dictOption']">
            <a-form-item :label="$t('m.eform.apptable.other.form_dictOption')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <dict-setting :dictOption="dictOption" @input="inputDict" :groupId="groupId" :canEdit="true"></dict-setting>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['sqlConfig']">
            <a-form-item :label="$t('m.eform.apptable.other.form_sqlConfig')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <sql-config-setting :sqlConfig="sqlConfig" @input="inputSqlConfig" :groupId="groupId" :show-parameter="true" :hidden-out-key="isQuery"></sql-config-setting>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['httpConfig']">
            <a-form-item :label="$t('m.eform.apptable.other.service_configuration')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <http-config-setting :httpConfig="httpConfig" @input="inputHttpConfig" :groupId="groupId"></http-config-setting>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['min']">
            <a-form-item :label="$t('m.eform.apptable.other.form_min')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="min" :placeholder="$t('m.eform.apptable.placeholder.form_min')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['max']">
            <a-form-item :label="$t('m.eform.apptable.other.form_max')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="max" :placeholder="$t('m.eform.apptable.placeholder.form_max')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['step']">
            <a-form-item :label="$t('m.eform.apptable.other.form_step')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="step" :placeholder="$t('m.eform.apptable.placeholder.form_step')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['minRows']">
            <a-form-item :label="$t('m.eform.apptable.other.form_minRows')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="minRows" :placeholder="$t('m.eform.apptable.placeholder.form_minRows')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['maxRows']">
            <a-form-item  :label="$t('m.eform.apptable.other.form_maxRows')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="maxRows" :placeholder="$t('m.eform.apptable.placeholder.form_maxRows')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24"
                 v-show="config[type] && config[type]['showTime'] ||
                        config[type] && config[type]['clearable'] ||
                        config[type] && config[type]['range'] ||
                        config[type] && config[type]['rangeNumber'] ||
                        config[type] && config[type]['multiple'] ||
                        config[type] && config[type]['useCode'] ||
                        config[type] && config[type]['allowHalf'] ||
                        config[type] && config[type]['drag'] ||
                        config[type] && config[type]['hidden'] ||
                        config[type] && config[type]['showSearch']
        ">
            <a-form-item :label="$t('m.eform.apptable.other.form_other_config')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-checkbox v-model="showTime" v-show="config[type] && config[type]['showTime']">{{ $t('m.eform.apptable.other.option_showTime') }}</a-checkbox>
              <a-checkbox v-model="clearable" v-show="config[type] && config[type]['clearable']">{{ $t('m.eform.apptable.other.option_clearable') }}</a-checkbox>
              <a-checkbox v-model="range" v-show="config[type] && config[type]['range']">{{ $t('m.eform.apptable.other.option_range') }}</a-checkbox>
              <a-checkbox v-model="rangeNumber" v-show="config[type] && config[type]['rangeNumber']">{{ $t('m.eform.apptable.other.option_range_number') }}</a-checkbox>
              <a-checkbox v-model="multiple" v-show="config[type] && config[type]['multiple']">{{ $t('m.eform.apptable.other.option_multiple') }}</a-checkbox>
              <a-checkbox v-model="useCode" v-show="config[type] && config[type]['useCode']">{{ $t('m.eform.apptable.other.option_useCode') }}</a-checkbox>
              <a-checkbox v-model="allowHalf" v-show="config[type] && config[type]['allowHalf']">{{ $t('m.eform.apptable.other.option_allowHalf') }}</a-checkbox>
              <a-checkbox v-model="drag" v-show="config[type] && config[type]['drag']">{{ $t('m.eform.apptable.other.option_drag') }}</a-checkbox>
              <a-checkbox v-model="hidden" v-show="config[type] && config[type]['hidden']">{{ $t('m.eform.apptable.other.option_hidden') }}</a-checkbox>
              <a-checkbox v-model="showSearch" v-show="config[type] && config[type]['showSearch']">{{ $t('m.eform.apptable.other.option_showSearch') }}</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['viewName']">
            <a-form-item  :label="$t('m.eform.apptable.other.form_viewName')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <view-code-tag v-model="viewName" :placeholder="$t('m.eform.apptable.placeholder.viewName')"
                                 :useParameter="isTable || isSubTable" :parameterConfig="parameterConfig"
                                 @setParameterConfig="setParameterConfig" :view-code="viewCode"
                                @selectFinished="selectViewOk" :groupId="groupId"></view-code-tag>
              <span>ViewCode：{{viewCode}}</span>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['keyField']">
            <a-form-item :label="$t('m.common.label.prompt')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <small>{{$t('m.eform.apptable.placeholder.prompt')}}</small>
            </a-form-item>
            <a-form-item :label="$t('m.eform.apptable.other.storage_field')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <view-col-select v-model="keyField" :viewCode="viewCode" :placeholder="$t('m.eform.apptable.placeholder.keyField')"></view-col-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['labelField']">
            <a-form-item :label="$t('m.eform.apptable.other.display_field')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <view-col-select v-model="labelField" :viewCode="viewCode" :placeholder="$t('m.eform.apptable.placeholder.labelField')"></view-col-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['fields']">
            <a-form-item :label="$t('m.eform.apptable.other.form_fields')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <KPageField v-model="fields" :viewCode="viewCode" :tableColList="tableColList"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['limit']">
            <a-form-item :label="$t('m.eform.apptable.other.form_limit')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-model="limit" :placeholder="$t('m.eform.apptable.placeholder.form_limit')" style="width: 100%;"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['bizPath']">
            <a-form-item :label="$t('m.eform.apptable.other.form_bizPath')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="bizPath" :placeholder="$t('m.eform.apptable.placeholder.form_bizPath')" allowClear/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="type === 'listType'">
            <a-form-item :label="$t('m.eform.apptable.other.form_listType')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select v-model="listType" :placeholder="$t('m.eform.apptable.placeholder.form_listType')" allowClear>
                <a-select-option value="text">text</a-select-option>
                <a-select-option value="picture">picture</a-select-option>
                <a-select-option value="picture-card">picture-card</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['linkage'] && (isQuery || isSubTable)">
            <a-form-item :label="$t('m.eform.formDesign.label.lian-dong-shu-xing')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-tooltip :title="$t('m.eform.formDesign.label.linkage-tooltip')">
                <a-checkbox v-model="enableLinkage">{{ $t('m.common.button.enable') }}</a-checkbox>
              </a-tooltip>
              <ych-multi-select-tag v-if="enableLinkage" v-model="linkage" :placeholder="$t('m.eform.formDesign.label.qing-xuan-ze-shang-ji-kong-jian')" :options="columnOptions" style="width: 200px; margin-left: 24px;"></ych-multi-select-tag>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['formatExpr']">
            <a-form-item :label="$t('m.eform.apptable.other.formatted_expression')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="formatExpr" :placeholder="$t('m.eform.apptable.placeholder.formatExpr')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['ruleCode']">
            <a-form-item :label="$t('m.system.sysfillrule.entity.ruleCode')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-fill-rule-tag v-model="ruleCode" :placeholder="$t('m.common.label.option_select')"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['customOrgFilterSql']">
            <a-form-item :label="$t('m.eform.apptable.other.customOrgFilterSql')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="customOrgFilterSql" :placeholder="$t('m.eform.apptable.placeholder.customOrgFilterSql')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['customOrgOrderSql']">
            <a-form-item :label="$t('m.eform.apptable.other.customOrgOrderSql')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="customOrgOrderSql" :placeholder="$t('m.eform.apptable.placeholder.customOrgOrderSql')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['label_wrapper'] && isQuery">
            <a-form-item :label="$t('m.eform.formDesign.label.kong-jian-zhan')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-slider :max="24" :min="0" v-model="compColSpan"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['label_wrapper'] && isQuery">
            <a-form-item :label="$t('m.eform.formDesign.label.biao-qian-zhan')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-slider :max="24" :min="0" v-model="labelColSpan" @change="wrapperColSpan = 24 - labelColSpan"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-show="config[type] && config[type]['label_wrapper'] && isQuery">
            <a-form-item :label="$t('m.eform.formDesign.label.shu-ru-kuang-zhan')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-slider :max="24" :min="0" v-model="wrapperColSpan"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{ $t('m.common.button.close') }}</a-button>
      <a-button v-if="isTable" key="saveToDataConfig" @click="saveToDataConfig">{{ $t('m.eform.apptable.other.button_copy_data')}}</a-button>
      <a-button v-if="isQuery && sql" key="syncDataConfig" @click="syncDataConfig">{{ $t('m.eform.apptable.other.button_update_data')}}</a-button>
      <a-button key="submit" type="primary" @click="handleOk">{{ $t('m.common.button.ok') }}</a-button>
    </template>
  </ych-modal>
</template>

<script>

  import DictSetting from './DictSetting'
  import SqlConfigSetting from './SqlConfigSetting'
  import HttpConfigSetting from './HttpConfigSetting'
  import ViewCodeTag from '../../select/tag/ViewCodeTag'
  import ViewColSelect from '../../select/tag/ViewColSelect'
  import KPageField from '../designer/packages/KPageField/index'
  import KChangeOption from '../designer/packages/KChangeOption/index'
  import {EFormConstant} from '../../EFormConstant'
  import {postAction} from '@/api/manage'
  import YchConstant from "@/api/YchConstant";
  import YchMultiSelectTag from '@/components/dict/YchMultiSelectTag'
  import SelectFillRuleTag from "../../../system/select/SelectFillRuleTag";

  export default {
    name: 'FormShowConfigDialog',
    components: {
      DictSetting,
      SqlConfigSetting,
      HttpConfigSetting,
      ViewCodeTag,
      ViewColSelect,
      KPageField,
      KChangeOption,
      EFormConstant,
      YchMultiSelectTag,
      SelectFillRuleTag,
    },
    props: {
      isTable: {
        type: Boolean,
        default: false
      },
      isQuery: {
        type: Boolean,
        default: false
      },
      isSubTable: {
        type: Boolean,
        default: false
      },
      tableColList:{
        type:Array,
        default: () => []
      },
      modelTreeMainData:{
        type:Array,
        default: () => []
      },
      groupId: {
        type: String,
        required: true
      },
    },
    data() {
      return {
        title: this.$t('m.common.label.operate'),
        visible: false,
        showTypeOptions: EFormConstant.showType,
        record: {},
        type: null,

        options: [],
        dictOption: {},
        sqlConfig: {},
        httpConfig: {},
        format: undefined,
        showTime: false,
        clearable: false,
        multiple: false,
        useCode: false,
        customOrgOrderSql: null,
        customOrgFilterSql: null,
        range: false,
        rangeNumber: false,
        min: null,
        max: null,
        step: null,
        allowHalf: false,
        showSearch: false,
        placeholder: null,
        minRows: null,
        maxRows: null,
        viewCode: null,
        viewName: null,
        keyField: null,
        labelField: null,
        fields: [],
        bizPath: null,
        limit: null,
        listType: undefined,
        drag: false,
        hidden: false,
        formatExpr: null,
        ruleCode: 'default_rule',
        linkage: null,
        enableLinkage: false,

        labelCol: {
          xs: {span: 24},
          sm: {span: 6},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        config: {
          hidden: {},
          input: {
            hidden: true,
            placeholder: this.isQuery,
            label_wrapper: true,
          },
          textarea: {
            minRows: true,
            maxRows: true,
            label_wrapper: true,
          },
          number: {
            min: true,
            max: true,
            step: true,
            placeholder: this.isQuery,
            label_wrapper: true,
            rangeNumber: this.isQuery,
          },
          select: {
            options: true,
            dictOption: true,
            sqlConfig: true,
            httpConfig: true,
            multiple: this.isTable || this.isQuery,
            clearable: this.isTable || this.isQuery,
            showSearch: this.isTable || this.isQuery,
            placeholder: this.isQuery,
            formatExpr: true,
            label_wrapper: true,
            linkage: true,
          },
          checkbox: {
            options: true,
            dictOption: true,
            sqlConfig: true,
            httpConfig: true,
            formatExpr: true,
            label_wrapper: true,
          },
          radio: {
            options: true,
            dictOption: true,
            sqlConfig: true,
            httpConfig: true,
            formatExpr: true,
            label_wrapper: true,
          },
          switch: {
            label_wrapper: true,
          },
          date: {
            format: true,
            showTime: true,
            clearable: true,
            range: this.isQuery,
            placeholder: this.isQuery,
            label_wrapper: true,
          },
          time: {
            format: true,
            clearable: true,
            placeholder: this.isQuery,
            label_wrapper: true,
          },
          rate: {
            max: true,
            allowHalf: true,
            label_wrapper: true,
          },
          slider: {
            min: true,
            max: true,
            step: true,
            label_wrapper: true,
          },
          serialno: {
            ruleCode: true,
            label_wrapper: true,
          },
          editor: {
            label_wrapper: true,
          },
          icon: {
            label_wrapper: true,
          },
          uploadFile: {
            multiple: true,
            bizPath: true,
            limit: true,
            drag: true,
            label_wrapper: true,
          },
          uploadImg: {
            multiple: true,
            bizPath: true,
            limit: true,
            listType: true,
            label_wrapper: true,
          },
          user: {
            multiple: true,
            useCode: true,
            customOrgOrderSql: true,
            customOrgFilterSql: true,
            placeholder: this.isQuery,
            label_wrapper: true,
            linkage: true,
          },
          dept: {
            multiple: true,
            useCode: true,
            customOrgOrderSql: true,
            customOrgFilterSql: true,
            placeholder: this.isQuery,
            label_wrapper: true,
          },
          page: {
            multiple: true,
            viewCode: true,
            viewName: true,
            keyField: true,
            labelField: true,
            fields: this.isTable || this.isSubTable,
            placeholder: this.isQuery,
            label_wrapper: true,
          },
          signature: {
            multiple: true,
          },
        },
        url: {
          parseSql: YchConstant.PREFIX_EFORM + '/engine/viewEngine/parseSql',
        },
        sql: null,
        dsCode: null,
        confirmLoading: false,
        labelColSpan: 8,
        wrapperColSpan: 16,
        compColSpan: 6,
        parameterConfig: [],
      }
    },
    computed: {
      columnOptions() {
        const result = []
        const temp = {}
        if (this.tableColList && this.tableColList.length > 0) {
          this.tableColList.forEach(row => {
            let value = row.colCode || row.value;
            let text = row.colName || row.text;
            if (value && text) {
              if (temp[value]) {
                return
              }
              result.push({
                value: value,
                text: text
              })
              temp[value] = true
            }
          })
        }
        if (this.modelTreeMainData && this.modelTreeMainData.length > 0) {
          this.modelTreeMainData.forEach(row => {
            let value = row.value;
            let text = row.title;
            if (value && text) {
              if (temp[value]) {
                return
              }
              result.push({
                value: value,
                text: text
              })
              temp[value] = true
            }
          })
        }
        return result
      },
    },
    methods: {
      open(json, record, sql, dsCode) {
        this.record = record ? record : {}
        this.title = this.$t('m.eform.apptable.entity.showConfig')
        this.title += this.record.colName ? ('——' + this.$locale(this.record.colName)) : ''
        this.type = this.record.showType
        this.sql = sql
        this.dsCode = dsCode
        const model = (json && json != '') ? JSON.parse(json) : {}

        this.initData(model)
      },
      initData(model) {
        this.format = model.format || undefined
        this.options = model.options || []
        this.dictOption = model.dictOption || {}
        this.sqlConfig = model.sqlConfig || {}
        this.httpConfig = model.httpConfig || {}
        this.showTime = !!model.showTime
        this.clearable = !!model.clearable
        this.multiple = !!model.multiple
        this.useCode = !!model.useCode
        this.customOrgOrderSql = model.customOrgOrderSql || null
        this.customOrgFilterSql = model.customOrgFilterSql || null
        this.range = !!model.range
        this.rangeNumber = !!model.rangeNumber
        this.min = model.min || model.min === 0 ? model.min : null
        this.max = model.max || model.max === 0 ? model.max : null
        this.step = model.step || model.step === 0 ? model.step : null
        this.allowHalf = !!model.allowHalf
        this.placeholder = model.placeholder || null
        this.minRows = model.minRows || model.minRows === 0 ? model.minRows : null
        this.maxRows = model.maxRows || model.maxRows === 0 ? model.maxRows : null
        this.viewCode = model.viewCode || null
        this.viewName = model.viewName || null
        this.keyField = model.keyField || null
        this.labelField = model.labelField || null
        this.fields = model.fields || []
        this.bizPath = model.bizPath || null
        this.limit = model.limit || model.limit === 0 ? model.limit : null
        this.listType = model.listType || undefined
        this.drag = !!model.drag
        this.hidden = !!model.hidden
        this.showSearch = !!model.showSearch
        this.formatExpr = model.formatExpr || null
        this.ruleCode = model.ruleCode || "default_rule"
        this.labelColSpan = typeof model.labelColSpan !== "undefined" ? model.labelColSpan : 8;
        this.wrapperColSpan = typeof model.wrapperColSpan !== "undefined" ? model.wrapperColSpan : 16;
        this.compColSpan = typeof model.compColSpan !== "undefined" ? model.compColSpan : 6;
        this.parameterConfig = model.parameterConfig || []
        this.linkage = model.linkage || null
        this.enableLinkage = !!model.enableLinkage

        this.visible = true
      },
      handleOk() {
        const model = {}
        if (this.config[this.type]['format'] && this.format) {
          model.format = this.format
        }
        if (this.config[this.type]['showTime'] && this.showTime) {
          model.showTime = this.showTime
        }
        if (this.config[this.type]['clearable'] && this.clearable) {
          model.clearable = this.clearable
        }
        if (this.config[this.type]['range'] && this.range) {
          model.range = this.range
        }
        if (this.config[this.type]['rangeNumber'] && this.rangeNumber) {
          model.rangeNumber = this.rangeNumber
        }
        if (this.config[this.type]['allowHalf'] && this.allowHalf) {
          model.allowHalf = this.allowHalf
        }
        if (this.config[this.type]['multiple'] && this.multiple) {
          model.multiple = this.multiple
        }
        if (this.config[this.type]['useCode'] && this.useCode) {
          model.useCode = this.useCode
        }
        if (this.config[this.type]['customOrgOrderSql'] && this.customOrgOrderSql) {
          model.customOrgOrderSql = this.customOrgOrderSql
        }
        if (this.config[this.type]['customOrgFilterSql'] && this.customOrgFilterSql) {
          model.customOrgFilterSql = this.customOrgFilterSql
        }
        if (this.config[this.type]['options'] && this.options && this.options.length > 0) {
          model.options = this.options
        }
        if (this.config[this.type]['dictOption'] && this.dictOption.dictCode) {
          model.dictOption = this.dictOption
        }
        if (this.config[this.type]['sqlConfig'] && this.sqlConfig.sqlCode) {
          model.sqlConfig = this.sqlConfig
        }
        if (this.config[this.type]['httpConfig'] && this.httpConfig.httpCode) {
          model.httpConfig = this.httpConfig
        }
        if (this.config[this.type]['min'] && (this.min || this.min === 0)) {
          model.min = this.min
        }
        if (this.config[this.type]['max'] && (this.max || this.max === 0)) {
          model.max = this.max
        }
        if (this.config[this.type]['step'] && (this.step || this.step === 0)) {
          model.step = this.step
        }
        if (this.config[this.type]['placeholder'] && this.placeholder) {
          model.placeholder = this.placeholder
        }
        if (this.config[this.type]['minRows'] && (this.minRows || this.minRows === 0)) {
          model.minRows = this.minRows
        }
        if (this.config[this.type]['maxRows'] && (this.maxRows || this.maxRows === 0)) {
          model.maxRows = this.maxRows
        }
        if (this.config[this.type]['viewCode'] && this.viewCode) {
          model.viewCode = this.viewCode
          if (this.parameterConfig && this.parameterConfig.length > 0) {
            model.parameterConfig = this.parameterConfig
          }
        }
        if (this.config[this.type]['viewName'] && this.viewName) {
          model.viewName = this.viewName
        }
        if (this.config[this.type]['keyField'] && this.keyField) {
          model.keyField = this.keyField
        }
        if (this.config[this.type]['labelField'] && this.labelField) {
          model.labelField = this.labelField
        }
        if (this.config[this.type]['fields'] && this.fields && this.fields.length > 0) {
          model.fields = this.fields
        }
        if (this.config[this.type]['bizPath'] && this.bizPath) {
          model.bizPath = this.bizPath
        }
        if (this.config[this.type]['limit'] && (this.limit || this.limit === 0)) {
          model.limit = this.limit
        }
        if (this.config[this.type]['listType'] && this.listType) {
          model.listType = this.listType
        }
        if (this.config[this.type]['drag'] && this.drag) {
          model.drag = this.drag
        }
        if (this.config[this.type]['hidden'] && this.hidden) {
          model.hidden = this.hidden
        }
        if (this.config[this.type]['showSearch'] && this.showSearch) {
          model.showSearch = this.showSearch
        }
        if (this.config[this.type]['formatExpr'] && this.formatExpr) {
          model.formatExpr = this.formatExpr
        }
        if (this.config[this.type]['ruleCode']) {
          model.ruleCode = this.ruleCode || 'default_rule'
        }
        if (this.config[this.type]['label_wrapper'] && this.isQuery) {
          model.labelColSpan = this.labelColSpan
        }
        if (this.config[this.type]['label_wrapper'] && this.isQuery) {
          model.wrapperColSpan = this.wrapperColSpan
        }
        if (this.config[this.type]['label_wrapper'] && this.isQuery) {
          model.compColSpan = this.compColSpan
        }
        if (this.config[this.type]['linkage'] && this.enableLinkage && this.linkage && (this.isQuery || this.isSubTable)) {
          model.enableLinkage = this.enableLinkage
          model.linkage = this.linkage
        }
        const modelStr = JSON.stringify(model)
        if (modelStr !== '{}') {
          this.$emit('selectFinished', modelStr)
        } else {
          this.$emit('selectFinished')
        }

        this.visible = false

        return model
      },
      handleCancel() {
        this.visible = false
      },
      inputDict(dictOption) {
        this.dictOption = dictOption
      },
      inputSqlConfig(sqlConfig) {
        this.sqlConfig = sqlConfig
      },
      inputHttpConfig(httpConfig) {
        this.httpConfig = httpConfig
      },
      saveToDataConfig() {
        const model = this.handleOk()
        this.$emit('saveToDataConfig', model, this.record)
      },
      selectViewOk(selectedRowKeys, selectionRows) {
        this.viewName = selectionRows[0].viewName
        this.viewCode = selectionRows[0].viewCode
      },
      syncDataConfig() {
        if (!this.sql) {
          this.messageUtil.warning(this.$t('m.eform.apptable.verify.tip_sql'))
          return
        }
        this.confirmLoading = true
        postAction(this.url.parseSql + '?dsCode=' + this.dsCode, {
          sql: this.sql
        }).then((res) => {
          if (res.success) {
            this.initTable(res.result)
          } else {
            this.messageUtil.warning(res.message)
          }
        }).finally(() => {
          this.confirmLoading = false
        })
      },
      initTable(tables) {
        if (!tables) {
          this.messageUtil.warning(this.$t('m.common.tip.return_data_null'))
          return
        }
        for (let i = 0; i < tables.length; i++) {
          const table = tables[i]
          for (let j = 0; j < table.columns.length; j++) {
            const column = table.columns[j]
            if (column.colAlias === this.record.colCode) {
              const model = (column.showConfig && column.showConfig != '') ? JSON.parse(column.showConfig) : {}

              // 暂时保留不变的，以后优化
              model.placeholder = this.placeholder || null

              return this.initData(model)
            }
          }
        }
      },
      setParameterConfig(parameterConfig){
        this.parameterConfig = parameterConfig;
      },
    }
  }
</script>
